package ma.ensao.egicom.bank.services.dao.imlementations;

import java.util.List;

import ma.ensao.egicom.bank.services.dao.interfaces.AccountDao;
import ma.ensao.egicom.bank.services.dao.interfaces.HibernateDaoBaseImplementationPatch;
import ma.ensao.egicom.bank.services.model.Account;

/**
 * Implémentation de l'interface AccountDao.
 * @author MILHI Yassine (milhi.yassinee@gmail.com)
 */
public class AccountDaoImpl extends HibernateDaoBaseImplementationPatch implements AccountDao {

    /**
     * {@inheritDoc}
     */
    @Override
    public void createAccount(Account account) {
        save(account);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void deleteAccount(Account account) {
        delete(account);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Account getAccountById(Long idAccount) {
        return load(idAccount, Account.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<Account> getAllUserAccounts() {

        return loadAll(Account.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void updateAccountBalance(Account account) {
        update(account);

    }

    /**
     * {@inheritDoc}
     */
    @Override
    @SuppressWarnings("unchecked")
    public List<Account> getAccountByProperty(String propertyName, Object value) {
        return (List<Account>) getOperationByProperty(propertyName, value, Account.class, "account").get(0);
    }

}
